package com.wll.aop.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：wanglulu
 * @date ： 2021/11/16 16:44
 * @description：全局异常捕获
 * @version: 1.0
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler({MissingServletRequestParameterException.class, ParamIsNullException.class})
    public Object getException(Exception e){
        log.error("request exception : ", e);
        Map<String, Object> map = new HashMap<>();
        map.put("code", "1000");
        map.put("msg", e.getMessage());
        return map;
    }




}
